// pages/upload/upload.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageSrc: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  handleUpload: function() {
    var that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      success: function(res) {
        wx.uploadFile({
          url: app.globalData.apiUrl + 'upload',
          filePath: res.tempFilePaths[0],
          name: 'avatar',
          success: function(res) {
            that.setData({
              imageSrc: res.data
            })
          },
        })
      }
    })
  },
  handleDownload: function() {
    wx.downloadFile({
      url: 'http://school-news.test/storage/avatars/CteaMQJ524bQqSeRYNOzV0g1rPRQlTgfd38zaAZM.png',
      success: function(res) {
        console.log(res)
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function(res) {
            console.log(res)
          }
        })
      }
    })
  }
})